package crm.view.Admin;

import crm.entity.Customer;

import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.util.List;
import java.util.Vector;

public class CustomInfo extends JFrame{


    public CustomInfo(List<Customer> list) {
        //如何由list来生成数据和表头
        Vector<Vector<Object>> vectordata=new Vector<>();

        for(Customer customer:list){
            Vector<Object> objs=new Vector<>();
            objs.add(customer.getCustomer_id());
            objs.add(customer.getCustomer_name());
            objs.add(customer.getCustomer_pwd());
            objs.add(customer.getCustomer_address());
            objs.add(customer.getCustomer_phone());
            objs.add(customer.getCredit());
            vectordata.add(objs);//objs是一条纪录对应的多个字段的vector列表
        }

        String[] labels={"编号","姓名","密码","地址","电话","信誉"};

        Vector<String> columnNames=new Vector<>();
        for(String label:labels){
            columnNames.add(label);
        }

        /*
         * 当Jtable使用vector作为入参时，需要明确第一个参数，
         * 要是一个嵌套了Vector<Object>（里面的每个元素对应一条数据记录的每个字段值）的一个Vector
         */
        JTable table=new JTable(vectordata, columnNames);
        //JTable table = new JTable(rowData, columnNames);


        JScrollPane scrollPane = new JScrollPane(table);


        this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
        // 创建内容面板
        JPanel panel = new JPanel();
        panel.setLayout(null);
        panel.setBorder(new TitledBorder(null, "查询客户基本信息", TitledBorder.LEADING,
                TitledBorder.TOP, null, null));

        this.getContentPane().add(panel);

        panel.add(scrollPane);
        scrollPane.setBounds(15, 15, 500, 200);
        scrollPane.setBorder(new TitledBorder(null, "客户基本信息",
                TitledBorder.LEADING, TitledBorder.TOP, null, null));
        this.setSize(620, 400);

        this.setLocationRelativeTo(null);
        this.setVisible(true);
    }
}
